Hey Yimeng!

So I'm finding it hard to explain how to make a time series of a shape feature, so here's some example code of what I mean.

So you're applying the code from this tutorial to your data. Right?


In [1]:
%config InlineBackend.figure_format = 'retina'
%matplotlib inline

import numpy as np
import scipy as sp
import matplotlib.pyplot as plt

import seaborn as sns
sns.set_style('white')

from misshapen import shape, nonshape

Load data


In [5]:
x = np.load('./exampledata.npy') # voltage series
x = x[:10000]
Fs = 1000 # sampling rate
f_range = (13,30) # frequency range of oscillation of interest
t = np.arange(0,len(x)/Fs,1/Fs) # time array

Compute shape features


In [6]:
findpt_kwargs = {'filter_fn':nonshape.bandpass_default,
                'filter_kwargs': {'w':3}}
define_true_oscillating_periods_kwargs = {'ampdiff_th':.5, 'timediff_th':.6}
df_P, df_T = shape.compute_shape_by_cycle(x, f_range, Fs,
                                          findpt_kwargs=findpt_kwargs,
                                          define_true_oscillating_periods_kwargs=define_true_oscillating_periods_kwargs)


WARNING: Error when estimating decaying zerocrossing after peak 22 at sample 1090. Therefore, the zerocrossing has been set to halfway between the two extrema.
/Users/scott/anaconda/lib/python3.6/site-packages/numpy/core/_methods.py:59: RuntimeWarning: Mean of empty slice.
  warnings.warn("Mean of empty slice.", RuntimeWarning)
/Users/scott/anaconda/lib/python3.6/site-packages/numpy/core/_methods.py:70: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)
/gh/bv/misshapen/shape.py:738: RuntimeWarning: invalid value encountered in true_divide
  trough_stats['half_decay_time']
/gh/bv/misshapen/shape.py:782: RuntimeWarning: invalid value encountered in true_divide
  peak_stats['half_decay_time']

How to make a time series of a shape feature


In [11]:
# Let's look at 3 columns of df_T,
# which has the shape features for each peak-to-peak (trough-centered) cycle
df = df_T[['rdsym_time', 'sample_lastE', 'sample_nextE']]
df.head(10)


Out[11]:
rdsym_time sample_lastE sample_nextE
0 -6 128 174
1 -26 174 222
2 -22 222 262
3 39 262 315
4 -3 315 344
5 -2 344 380
6 16 380 434
7 11 434 487
8 0 487 513
9 10 513 549

In [12]:
rdsym_time_ts = np.zeros(len(x))
N_cycles = len(df)
for i in range(N_cycles):
    rdsym_time_ts[df['sample_lastE'][i]:df['sample_nextE'][i]] = df['rdsym_time'][i]

In [13]:
plt.plot(rdsym_time_ts)


Out[13]:
[<matplotlib.lines.Line2D at 0x11efe2080>]

Then, we can analyze how the rise-decay symmetry of beta oscillations changes with movement

Treat this 'rdsym_time_ts' as you treated the beta amplitude time series in your notebook learnshape/dg/data_processing/load_neural_data.ipynb

Do we see a change in the rise-decay symmetry of the beta oscillations around the time of movement onset in subject bp?


In [ ]: